package ${package.Service};

import com.song.tools.mvc.service.AggregationService;
import com.song.tools.mvc.validator.ValidationResult;
import com.song.tools.mvc.validator.ValidatorChain;
import ${package.QueryRequest}.${QueryRequestName};
import ${package.SaveRequest}.${SaveRequestName};
import ${package.UpdateRequest}.${UpdateRequestName};
import ${package.DeleteResponse}.${DeleteResponseName};
import ${package.QueryResponse}.${QueryResponseName};
import ${package.SaveResponse}.${SaveResponseName};
import ${package.UpdateResponse}.${UpdateResponseName};
import ${package.ImportDto}.${ImportDtoName};
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * <p>
 * ${table.comment!} 服务类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
public interface ${ServiceName} extends AggregationService<${PrimaryKeyType}, ${QueryRequestName}, ${QueryResponseName},
        ${SaveRequestName}, ${SaveResponseName}, ${UpdateRequestName}, ${UpdateResponseName}, ${DeleteResponseName}, HttpServletResponse> {

    @Override
    default ValidationResult validateOnSave(${SaveRequestName} ${entityLowerCaseFirstOne}SaveRequest) {
        ValidatorChain validatorChain = new ValidatorChain();

        // save时校验参数
        return validatorChain.validate();
    }


    @Override
    default ValidationResult validateOnUpdate(${UpdateRequestName} ${entityLowerCaseFirstOne}UpdateRequest) {
        ValidatorChain validatorChain = new ValidatorChain();

        // update时校验参数
        return validatorChain.validate();
    }


    /**
     * 导入前的数据校验
     *
     * @param importDtos 导入dto
     */
    default ValidationResult validateOnImport(List<${ImportDtoName}> importDtos) {
        for (${ImportDtoName} importDto : importDtos) {
            ValidatorChain validatorChain = new ValidatorChain();

            // import时校验参数
            ValidationResult validationResult = validatorChain.validate();
            if (!validationResult.isValid()) {
                return validationResult;
            }
        }
        return ValidationResult.success();
    }
}

